package com.hunttown.mes.dao;

import com.hunttown.common.dao.base.BaseDao;
import com.hunttown.common.domain.Query;
import com.hunttown.mes.domain.TransportTask;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * created by wangjunfu on 2021-02-24 16:00:07
 */
@Repository
public class TransportTaskDao extends BaseDao {
    private static final Logger logger = LoggerFactory.getLogger(TransportTaskDao.class);

    public TransportTask insert(final TransportTask transportTask) {
        insert("TransportTask.insert", transportTask);
        return transportTask;
    }

    public Boolean updateInfoById(final TransportTask transportTask) {
        return update("TransportTask.updateInfoById", transportTask) > 0;
    }

    public Boolean updateInfoByQuery(final Query query) {
        return update("TransportTask.updateInfoByQuery", query) > 0;
    }

    public TransportTask selectById(final Integer id, final Integer entId) {
        Query query = Query.noPage();
        query.put("id", id);
        query.put("entId", entId);
        return queryForObject("TransportTask.selectById", query);
    }

    public List<TransportTask> selectByQuery(final Query query) {
        return queryForList("TransportTask.selectByQuery", query);
    }

    public Long countByQuery(final Query query) {
        return queryForObject("TransportTask.countByQuery", query);
    }

    public List<TransportTask> selectMytaskByQuery(final Query query) {
        return queryForList("TransportTask.selectMytaskByQuery", query);
    }

    public Long countMytaskByQuery(final Query query) {
        return queryForObject("TransportTask.countMytaskByQuery", query);
    }

    public Boolean deleteById(final Integer id, final Integer entId) {
        TransportTask transportTask = new TransportTask();
        transportTask.setDeleteFlag(1);
        transportTask.setId(id);
        transportTask.setEntId(entId);

        return update("TransportTask.updateInfoById", transportTask) > 0;
    }

    //物理删除不可恢复，慎用！
    public Boolean deleteByIdForPhysical(final Integer id) {
        Query query = Query.noPage();
        query.put("id", id);
        return delete("TransportTask.deleteById", query) > 0;
    }
}